Completed
Push — js-scrutinizing ( ccc639...ed62f5 )
by Maxence
02:15
created

navdiv.fillMembersSearch   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 9.4285
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: nav */
31
/** global: actions */
32
/** global: curr */
33
/** global: api */
34
35
36
var elements = {
37
38
	newTypeDefinition: null,
39
	newType: null,
40
	newSubmit: null,
41
	newName: null,
42
	navigation: null,
43
	circlesList: null,
44
	emptyContent: null,
45
	mainUI: null,
46
	mainUIMembers: null,
47
	membersSearchResult: null,
48
49
	joinCircleAccept: null,
50
	joinCircleReject: null,
51
	joinCircleRequest: null,
52
	joinCircleInvite: null,
53
	joinCircle: null,
54
	leaveCircle: null,
55
	addMember: null,
56
57
58
	initElements: function () {
59
60
		elements.newTypeDefinition = $('#circles_new_type_definition');
61
		elements.newType = $('#circles_new_type');
62
		elements.newSubmit = $('#circles_new_submit');
63
		elements.newName = $('#circles_new_name');
64
		elements.navigation = $('#app-navigation.circles');
65
		elements.circlesList = $('#circles_list');
66
		elements.emptyContent = $('#emptycontent');
67
		elements.mainUI = $('#mainui');
68
		elements.mainUIMembers = $('#memberslist_table');
69
		elements.membersSearchResult = $('#members_search_result');
70
71
		elements.joinCircleAccept = $('#joincircle_acceptinvit');
72
		elements.joinCircleReject = $('#joincircle_rejectinvit');
73
		elements.joinCircleRequest = $('#joincircle_request');
74
		elements.joinCircleInvite = $('#joincircle_invit');
75
		elements.joinCircle = $('#joincircle');
76
		elements.leaveCircle = $('#leavecircle');
77
		elements.addMember = $('#addmember');
78
79
		this.initElementsActions();
80
	},
81
82
83
	initUI: function () {
84
		elements.newTypeDefinition.children('div').fadeOut(0);
85
		$('#circles_new_type_' + elements.newType.children('option:selected').val()).fadeIn(
86
			0);
87
88
		elements.newType.hide();
89
		elements.newSubmit.hide();
90
		elements.newTypeDefinition.hide();
91
92
		$('.icon-circles').css('background-image',
93
			'url(' + OC.imagePath('circles', 'colored') + ')');
94
95
		elements.membersSearchResult.hide();
96
	},
97
98
99
	initElementsActions: function () {
100
101
		elements.joinCircle.on('click', function () {
102
			api.joinCircle(curr.circle, actions.joinCircleResult);
103
		});
104
105
		elements.leaveCircle.on('click', function () {
106
			api.leaveCircle(curr.circle, actions.leaveCircleResult);
107
		});
108
109
		elements.joinCircleAccept.on('click', function () {
110
			api.joinCircle(curr.circle, actions.joinCircleResult);
111
		});
112
113
		elements.joinCircleReject.on('click', function () {
114
			api.leaveCircle(curr.circle, actions.leaveCircleResult);
115
		});
116
117
		elements.addMember.on('input propertychange paste focus', function () {
118
			actions.searchMembersRequest($(this).val().trim());
119
		}).blur(function () {
120
			elements.membersSearchResult.fadeOut(400);
121
		});
122
	},
123
124
125
	/**
126
	 *
127
	 */
128
	initAnimationNewCircle: function () {
129
130
		elements.newName.on('keyup', function () {
131
			actions.onEventNewCircleName();
132
		});
133
134
		elements.newType.on('change', function () {
135
			actions.onEventNewCircleType();
136
		});
137
138
		elements.newSubmit.on('click', function () {
139
			api.createCircle(elements.newType.val(), elements.newName.val(),
140
				actions.createCircleResult);
141
		});
142
143
	},
144
145
146
	fillMembersSearch: function (exact, partial) {
147
		this.fillExactMembersSearch(exact);
148
		this.fillPartialMembersSearch(partial);
149
		elements.membersSearchResult.children().first().css('border-top-width', '0px');
150
	},
151
152
	fillExactMembersSearch: function (exact) {
153
154
		$.each(exact, function (index, value) {
155
			elements.membersSearchResult.append(
156
				'<div class="members_search exact" searchresult="' +
157
				value.value.shareWith + '">' + value.label + '   (' +
158
				value.value.shareWith + ')</div>');
159
		});
160
161
	},
162
163
	fillPartialMembersSearch: function (partial) {
164
		$.each(partial, function (index, value) {
165
			var currSearch = $('#addmember').val().trim();
166
			var line = value.label + '   (' + value.value.shareWith + ')';
167
			if (currSearch.length > 0) {
168
				line =
169
					line.replace(new RegExp('(' + currSearch + ')', 'gi'),
170
						'<b>$1</b>');
171
			}
172
173
			elements.membersSearchResult.append(
174
				'<div class="members_search" searchresult="' +
175
				value.value.shareWith +
176
				'">' + line + '</div>');
177
		});
178
179
	},
180
181
182
	displayMembers: function (members) {
183
184
		elements.mainUIMembers.emptyTable();
185
186
		if (members === null) {
187
			elements.mainUIMembers.hide(200);
188
			return;
189
		}
190
191
		elements.mainUIMembers.show(200);
192
		for (var i = 0; i < members.length; i++) {
193
			elements.mainUIMembers.append(this.generateTmplMember(members[i]));
194
		}
195
196
		if (curr.circleLevel >= 6) {
197
			elements.mainUIMembers.children("[member-level!='9']").each(function () {
198
				$(this).children('.delete').show(0);
199
			});
200
201
			elements.mainUIMembers.children('.delete').on('click', function () {
202
				var member = $(this).parent().attr('member-id');
203
				api.removeMember(curr.circle, member, actions.removeMemberResult);
204
			});
205
		}
206
207
	}
208
209
};